OpenWeb(String) method
Posted
by ybbest
on YBBest
See other posts from YBBest
or by ybbest
Published on Thu, 14 Oct 2010 10:39:37 +0000
Indexed on
2010/12/30
22:01 UTC
Read the original article
Hit count: 245
SharePoint 2010
I guess this is a SharePoint beginner problem ,however it took me a while to figure out what the problem is and I will blog it to help me to remember. Basically I wrote the following code to grab some list item from my SharePoint subsite http://win-oirj50igics/RestAPI,however I got the error stating that :
“<nativehr>0×80070002</nativehr><nativestack></nativestack>There is no Web named / http://win-oirj50igics/RestAPI”.
The problem is that OpenWeb(String) method returns the web site that is located at the specified server-relative or site-relative URL. It is the relative URL , so after I changed http://win-oirj50igics/RestAPI to RestAPI, everything works fine.
using (SPSite site = new SPSite(http://win-oirj50igics/))
{
SPWeb web = site.OpenWeb("http://win-oirj50igics/RestAPI");
SPQuery query = new SPQuery();
query.Query = camlDocument.InnerXml;
SPListItemCollection items = web.Lists["Songs"].GetItems(query);
IEnumerable<Song> sortedItems =
from item in items.OfType<SPListItem>()
orderby item.Title
select new Song {SongName = item.Title, SongID = item.ID};
songs.AddRange(sortedItems);
}
© YBBest or respective owner